package common;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import javax.net.ssl.SSLSocket;

public class Sender extends Thread{

	private SSLSocket socket;
	private Buffer buffer;
	
	public Sender(SSLSocket socket){
		this.socket = socket;
		buffer = new Buffer();
	}
	
	public void run(){
		PrintWriter out = null;
		try {
			out = new PrintWriter(
					  new BufferedWriter(
					  new OutputStreamWriter(
					  socket.getOutputStream())));
		} catch (IOException e) {
			e.printStackTrace();
		}
	    
		while (true){
			out.println(buffer.poll());
		    out.flush();
		}
	}
	
	public synchronized void send(String str){
		buffer.offer(str);
	}
}
